import Vue from "vue";
import VueRouter from "vue-router";
Vue.use(VueRouter);

// 解决在个人中心，再次点击跳转个人中心的的报错
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
	return originalPush.call(this, location).catch((err) => err);
};
import Login from "@/views/login";
import Layout from "@/views/layout/Layout.vue";

// const routes = [
// 	// 重定向
// 	{
// 		path: "/",
// 		redirect: "/home",
// 	},
// 	// 登录页
// 	{
// 		path: "/login",
// 		component: Login,
// 	},
// 	// 后台首页
// 	{
// 		path: "/",
// 		component: Layout,
// 		redirect: "/home",
// 		meta: { path: "/home", title: "后台首页" },
// 		children: [
// 			{
// 				path: "/home",
// 				component: () => import("@/views/home"),
// 			},
// 		],
// 	},
// 	// 订单管理
// 	{
// 		path: "/",
// 		component: Layout,
// 		redirect: "/order",
// 		meta: { path: "/order", title: "订单管理" },
// 		children: [
// 			{
// 				path: "/order",
// 				component: () => import("@/views/order"),
// 			},
// 			{
// 				path:'/order/details/:id',
// 				meta: { path: "/order/details", title: "订单详情" },
// 				component:()=>import('@/views/order/details')
// 			}
// 		],
// 	},
// 	// 商品管理
// 	{
// 		path: "/goods",
// 		component: Layout,
// 		redirect: "/goods/list",
// 		meta: { path: "/goods", title: "商品管理" },
// 		children: [
// 			{
// 				path: "/goods/list",
// 				meta: { path: "/goods/list", title: "商品列表" },
// 				component: () => import("@/views/goods/goods-list"),
// 			},
// 			{
// 				path: "/goods/add",
//         meta: { path: "/goods/add", title: "商品添加" },
// 				component: () => import("@/views/goods/goods-add"),
// 			},
// 			{
// 				path: "/goods/cate",
//         meta: { path: "/goods/cate", title: "商品分类" },
// 				component: () => import("@/views/goods/goods-cate"),
// 			},
// 		],
// 	},
// 	// 店铺管理
// 	{
// 		path: "/",
// 		component: Layout,
// 		redirect: "/shop",
// 		meta: { path: "/shop", title: "店铺管理" },
// 		children: [
// 			{
// 				path: "/shop",
// 				component: () => import("@/views/shop"),
// 			},
// 		],
// 	},
// 	// 账号管理
// 	{
// 		path: "/account",
// 		component: Layout,
// 		redirect: "/account/list",
//     meta: { path: "/account", title: "账号管理" },
// 		children: [
// 			{
// 				path: "/account/list",
//         meta: { path: "/account/list", title: "账号列表" },
// 				component: () => import("@/views/account/account-list.vue"),
// 			},
// 			{
// 				path: "/account/add",
//         meta: { path: "/account/add", title: "添加账号" },
// 				component: () => import("@/views/account/account-add.vue"),
// 			},
// 			{
// 				path: "/account/modify",
//         meta: { path: "/account/modify", title: "修改密码" },
// 				component: () => import("@/views/account/account-modify.vue"),
// 			},
// 			{
// 				path: "/account/person",
//         meta: { path: "/account/person", title: "个人中心" },
// 				component: () => import("@/views/account/account-person.vue"),
// 			},
// 		],
// 	},
// 	// 销售统计
// 	{
// 		path: "/total",
// 		component: Layout,
// 		redirect: "/total/goods",
//     meta: { path: "/total", title: "销售统计" },
// 		children: [
// 			{
// 				path: "/total/goods",
//         meta: { path: "/total/goods", title: "商品统计" },
// 				component: () => import("@/views/total/total-goods.vue"),
// 			},
// 			{
// 				path: "/total/order",
//         meta: { path: "/total/order", title: "订单统计" },
// 				component: () => import("@/views/total/total-order.vue"),
// 			},
// 		],
// 	},
// 	// 404错误路由
// 	{
// 		path:'*',
// 		redirect:'/404'
// 	},
// 	{
// 		path:'/404',
// 		component:()=>import('@/views/404')
// 	}
// ];

// 静态路由
export let constantRoutes = [
	// 重定向
	{
		path: "/",
		redirect: "/home",
		hidden:true
	},
	// 登录页
	{
		path: "/login",
		component: Login,
		hidden:true
	},
	// 后台首页
	{
		path: "/home",
		component: Layout,
		redirect: "/home",
		meta: { path: "/home", title: "后台首页",level:1,icon:'icon-shouyefill' },
		children: [
			{
				path: "/home",
				component: () => import("@/views/home"),
			},
		],
	},
];
// 动态路由

export let asyncRoutes = [
	// 订单管理
	{
		path: "/order",
		component: Layout,
		redirect: "/order",
		meta: { path: "/order", title: "订单管理", roles: ["super"],level:1,icon:'icon-shouye' },
		children: [
			{
				path: "/order",
				component: () => import("@/views/order"),
			},
			{
				path: "/order/details/:id",
				meta: { path: "/order/details", title: "订单详情" },
				component: () => import("@/views/order/details"),
			},
		],
	},
	// 商品管理
	{
		path: "/goods",
		component: Layout,
		redirect: "/goods/list",
		meta: { path: "/goods", title: "商品管理",level:2,icon:'icon-shangpin' },
		children: [
			{
				path: "/goods/list",
				meta: { path: "/goods/list", title: "商品列表" },
				component: () => import("@/views/goods/goods-list"),
			},
			{
				path: "/goods/add",
				meta: {
					path: "/goods/add",
					title: "商品添加",
					roles: ["super"],
				},
				component: () => import("@/views/goods/goods-add"),
			},
			{
				path: "/goods/cate",
				meta: { path: "/goods/cate", title: "商品分类" },
				component: () => import("@/views/goods/goods-cate"),
			},
		],
	},
	// 店铺管理
	{
		path: "/shop",
		component: Layout,
		redirect: "/shop",
		meta: { path: "/shop", title: "店铺管理", roles: ["super"],level:1,icon:'icon-jinrudianpu' },
		children: [
			{
				path: "/shop",
				component: () => import("@/views/shop"),
			},
		],
	},
	// 账号管理
	{
		path: "/account",
		component: Layout,
		redirect: "/account/list",
		meta: { path: "/account", title: "账号管理",level:2,icon:'icon-user' },
		children: [
			{
				path: "/account/list",
				meta: {
					path: "/account/list",
					title: "账号列表",
					roles: ["super"],
				},
				component: () => import("@/views/account/account-list.vue"),
			},
			{
				path: "/account/add",
				meta: {
					path: "/account/add",
					title: "添加账号",
					roles: ["super"],
				},
				component: () => import("@/views/account/account-add.vue"),
			},
			{
				path: "/account/modify",
				meta: { path: "/account/modify", title: "修改密码" },
				component: () => import("@/views/account/account-modify.vue"),
			},
			{
				path: "/account/person",
				meta: { path: "/account/person", title: "个人中心" },
				component: () => import("@/views/account/account-person.vue"),
			},
		],
	},
	// 销售统计
	{
		path: "/total",
		component: Layout,
		redirect: "/total/goods",
		meta: { path: "/total", title: "销售统计", roles: ["super"],level:2,icon:'icon-tongji' },
		children: [
			{
				path: "/total/goods",
				meta: { path: "/total/goods", title: "商品统计" },
				component: () => import("@/views/total/total-goods.vue"),
			},
			{
				path: "/total/order",
				meta: { path: "/total/order", title: "订单统计" },
				component: () => import("@/views/total/total-order.vue"),
			},
		],
	},
];
// 错误路由
export let errorRoutes = [
	// 404错误路由
	{
		path: "*",
		redirect: "/404",
	},
	{
		path: "/404",
		component: () => import("@/views/404"),
	},
];

const router = new VueRouter({
	routes:constantRoutes
});

export default router;
